package com.falsemen.web.controller;

import com.falsemen.web.entity.Player;
import com.falsemen.web.mapper.PlayerMapper;
import com.falsemen.web.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping
public class PlayerController {

    @Autowired
    private PlayerMapper playerMapper;

    @Autowired
    private MailService mailService;

    @RequestMapping(value = "/insert" ,method = RequestMethod.POST)
    public void save(Player user) {
        playerMapper.insert(user);
        String txt;
        txt = "欢迎" + user.getName() + "加入《反人类联盟》游戏小组";
        mailService.sendSimpleMail(user.getEmail(), "欢迎你加入反人类联盟", txt);
    }

    @RequestMapping("/list")
    public String list(Model model) {
        List<Player> players=playerMapper.getPlayerList();
        model.addAttribute("players", players);
        return "list";
    }
}
